<template>
    <div class="m-default">
        <section class="m-hotlist">
            <h3 class="title">热门搜索</h3>
            <ul class="list">
                <li class="item f-bd f-bd-full" v-for="item in hotList" :key="item.first" @click="search(item.first)">
                    <a class="link" href="javascript:void(0);">{{item.first}}</a>
                </li>
            </ul>
        </section>
        <section class="m-history">
            <ul class="list">
                <li class="item" v-for="(item,index) in Song_history" :key="item">
                    <i class="iconfont icon-lishi"></i>
                    <div class="histyr f-bd f-bd-btm">
                        <span class="link f-thide" @click="search(item)">{{item}}</span>
                        <figure class="close" @click="delete_history(index)">
                            <i class="iconfont icon-x"></i>
                        </figure>
                    </div>
                </li>
            </ul>
        </section>
    </div>
</template>
<script>
import { get_search_hotList,get_song_history,set_song_history,clear_song_history } from "@/api";
export default {
    data() {
        return {
            hotList: [],
            Song_history:[]
        };
    },
    mounted() {
        get_search_hotList().then(res => {
            this.hotList = res.data.result.hots;
        });
        //获取搜索历史记录
        this.Song_history = get_song_history()
    },
    methods:{
        search(keyword){
            this.$parent.$refs.input_box.search(keyword)
        },
        
        delete_history(index){
            this.Song_history.splice(index,1)
            if(this.Song_history.length === 0){
                clear_song_history()
            }else{
                set_song_history(this.Song_history)
            }
        }
    }
};
</script>
<style lang="less" scoped>
.m-hotlist {
    padding: 15px 10px 0;
}
.m-hotlist .title {
    font-size: 12px;
    line-height: 12px;
    color: #666;
}
.m-hotlist .list {
    margin: 10px 0 7px;
}
.m-hotlist .item {
    display: inline-block;
    height: 32px;
    margin-right: 8px;
    margin-bottom: 8px;
    padding: 0 14px;
    font-size: 14px;
    line-height: 32px;
    color: #333;
}
.m-hotlist .item:after {
    border-color: #d3d4da;
    border-radius: 32px;
}
.f-bd {
    position: relative;
}

.f-bd:after {
    position: absolute;
    z-index: 2;
    content: "";
    top: 0;
    left: 0;
    pointer-events: none;
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    -webkit-transform-origin: top left;
    -ms-transform-origin: top left;
    transform-origin: top left;
    border: 0 solid rgba(0, 0, 0, 0.1);
}
.f-bd-full:after {
    border-width: 1px;
}
.f-bd-btm:after {
    border-bottom-width: 1px;
}
@media screen and (-webkit-min-device-pixel-ratio: 1.5) {
    .f-bd:after,
    .u-cover:after,
    .u-face:after {
        width: 150%;
        height: 150%;
        -webkit-transform: scale(0.666666);
        -ms-transform: scale(0.666666);
        transform: scale(0.666666);
    }
}
@media screen and (-webkit-min-device-pixel-ratio: 2) {
    .f-bd:after {
        width: 200%;
        height: 200%;
        -webkit-transform: scale(0.5);
        -ms-transform: scale(0.5);
        transform: scale(0.5);
    }
}
.m-history {
    .icon-lishi {
        margin: 0 10px;
        font-size: 15px;
        color: #d3d4da;
    }

    .icon-x {
        font-size: 14px;
        color: #d3d4da;
    }
}
.m-history .item,
.m-history .item .histyr {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
    height: 45px;
}
.m-history .item .histyr {
    position: relative;
}
.m-history .item .histyr:after {
    border-color: rgba(0, 0, 0, 0.1);
}
.m-history .item .histyr,
.m-history .item .link {
    -webkit-box-flex: 1;
    -webkit-flex: 1;
    -ms-flex: 1;
    flex: 1;
    width: 1%;
}
.m-history .item .link {
    margin-right: 10px;
}
.m-history .item .close {
    -webkit-box-flex: 0;
    -webkit-flex: 0 0 auto;
    -ms-flex: 0 0 auto;
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    line-height: 32px;
}
.m-history .u-svg-close {
    margin-left: 2px;
}
.m-history .u-svg-histy {
    margin: 0 10px;
}
</style>